define(function () {
  var jx1 = function () {
       $.get('./data/shan.json',function(responseText,responseState,responseObj){
        // console.log(responseText[0]);
         var data = responseText[0].data;
         var left = data.categories;
         var right = data.products;
        //  console.log(left);
        //  console.log(right);
        //  console.log(responseState);
        //  console.log(responseObj);
        var str1 = '';
        var arr = [];
        for(var i in left){
          var id = left[i].id;
          var name = left[i].name;
          var flag = left[i].flag;
          // console.log(id);
          // console.log(name);
          // console.log(flag);
          arr.push(left[i].id);
          if(flag != ''){
            str1 += `<div class="lis2" style="background:url('`+flag+`') no-repeat right top;background-size:30%"><span></span>`+name+`</div>`;
          }else {
            str1 += `<div class="lis2"><span></span>`+name+`</div>`;
          }
        }
        $('.left2').html(str1);
        //console.log(arr);
        var $lis = $(".left2>div");
        $lis.click(function () {
          var count = $(this).index();
          $('.bp').eq(count).css('display','block').siblings().css('display','none');
          $(document.body).scrollTop(0);
          $(this).children('span').css('backgroundColor','yellow');
          $(this).siblings().children('span').css('backgroundColor','transparent');
        })

        // var arr1 =[];
        // for(var i in right){
        //   console.log(i);
        //   //arr1.push(i);
        // }
        var str2 = '';
        for(var i of arr){
            var sp = right[i];
          //  console.log(sp)
            var str3 = '';
            for(var j in sp){
              //console.log(sp[j])
              var app_mimg = sp[j].app_mimg;
              var keywords = sp[j].keywords;
              var partner_price = sp[j].partner_price;
              var d_price = sp[j].d_price;
              var name = sp[j].name;
              var long_name = sp[j].long_name;
              var org_source_value = sp[j].org_source_value;
              var pm_desc = sp[j].pm_desc;
              var xl = long_name.substring(name.length,long_name.length);
                  if(d_price == undefined){
                      if(org_source_value == 1){
                        if(pm_desc == ''){
                          str3 +=`<div>
                          <div class="f1">
                          <img src=`+app_mimg+` alt="">
                          </div>
                          <div class="f2">
                          <p>`+long_name+`</p>
                          <span class="span1">精选</span><span class="span2">买一送一</span>
                          <h4>`+xl+`</h4>
                          <h5>￥`+partner_price+`</h5>
                          <div class="jia">
                          <i class="icon iconfont icon-jiahao"></i>
                          </div>
                          </div>
                          </div>`
                        }else {
                          str3 +=`<div>
                          <div class="f1">
                          <img src=`+app_mimg+` alt="">
                          </div>
                          <div class="f2">
                          <p>`+long_name+`</p>
                          <span class="span1">精选</span>
                          <h4>`+xl+`</h4>
                          <h5>￥`+partner_price+`</h5>
                          <div class="jia">
                          <i class="icon iconfont icon-jiahao"></i>
                          </div>
                          </div>
                          </div>`
                        }
                      }else {
                        str3 +=`<div>
                        <div class="f1">
                        <img src=`+app_mimg+` alt="">
                        </div>
                        <div class="f2">
                        <p>`+long_name+`</p>
                        <span style='border:none' class="span1"></span>
                        <h4>`+xl+`</h4>
                        <h5>￥`+partner_price+`</h5>
                        <div class="jia">
                        <i class="icon iconfont icon-jiahao"></i>
                        </div>
                        </div>
                        </div>`
                      }
                  }else {
                      if(org_source_value == 1){
                        if(pm_desc == ''){
                          str3 +=`<div>
                          <div class="f1">
                          <img src=`+app_mimg+` alt="">
                          </div>
                          <div class="f2">
                          <p>`+long_name+`</p>
                          <span class="span1">精选</span><span class="span2">买一送一</span>
                          <h4>`+xl+`</h4>
                          <h5>￥`+partner_price+` <a>￥`+d_price+`</a></h5>
                          <div class="jia">
                          <i class="icon iconfont icon-jiahao"></i>
                          </div>
                          </div>
                          </div>`

                        }else {
                          str3 +=`<div>
                          <div class="f1">
                          <img src=`+app_mimg+` alt="">
                          </div>
                          <div class="f2">
                          <p>`+long_name+`</p>
                          <span class="span1">精选</span>
                          <h4>`+xl+`</h4>
                          <h5>￥`+partner_price+` <a>￥`+d_price+`</a></h5>
                          <div class="jia">
                          <i class="icon iconfont icon-jiahao"></i>
                          </div>
                          </div>
                          </div>`
                        }
                      }else {
                        str3 +=`<div>
                        <div class="f1">
                        <img src=`+app_mimg+` alt="">
                        </div>
                        <div class="f2">
                        <p>`+long_name+`</p>
                        <span style='border:none' class="span1">
                        <h4>`+xl+`</h4>
                        <h5>￥`+partner_price+` <a>￥`+d_price+`</a></h5>
                        <div class="jia">
                        <i class="icon iconfont icon-jiahao"></i>
                        </div>
                        </div>
                        </div>`
                      }
                  }
            }
            str2 +=`<div class="bp">`+str3+`</div>`;
        }
        $('.xy').html(str2);

      })
  }
  return {
      jx1 : jx1
  };

})
